#include "main_service.h"

namespace anet {
	namespace tcp {
		CMainService::CMainService() {
			m_service = std::make_unique<asio::io_context>();
			m_work = std::make_unique<asio::io_context::work>(*m_service);
		}

		CMainService::~CMainService() {
			m_service->stop();
		}

		CMainService& CMainService::instance() {
			static CMainService gInstance;
			return gInstance;
		}

		bool CMainService::run(int count) {
			return m_service->poll() > 0;
		}

		void CMainService::post(std::function<void()> func) {
			asio::post(*m_service, std::move(func));
		}
	}
}
